# -*- coding: utf-8 -*-
import os
from flask_script import Manager, Server
from app import create_app
from app.models import *

app = create_app(os.getenv('FLASK_CONFIG') or 'default')
app.config['DEBUG'] = True
app.config['JSON_AS_ASCII'] = False
# app.config['SECRET_KEY'] = 'super secret key'
db.init_app(app)
manager = Manager(app)
manager.add_command("runserver", Server(host="127.0.0.1", port=8543, use_debugger=True))


@manager.command
def dev():
    """开发者用于实时监控代码，在网页端同步更新，提高开发效率"""
    from livereload import Server  # 导入监控包
    live_server = Server(app.wsgi_app)
    live_server.watch('**/*.*')  # 可用正则表达式，此处用于监测整个项目文件，
    live_server.serve(open_url=True)  # True表示自己打开浏览器


if __name__ == '__main__':
    manager.run()
    # 本地调试
    # app.run(port=8543,debug=True)
